package com.sum.slike.simple;

import com.sum.slike.*;
import com.sum.slike.utils.PixelUtil;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.app.Context;
import ohos.media.image.PixelMap;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;

public class ExampleOhosTest {
    @Test
    public void testScreenHeight() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();

        PixelUtil.initContext(context);
        int height = PixelUtil.screenHeight();
        System.out.println("height: " + height);
        Assert.assertTrue(height > 0);
        Assert.assertEquals(height, 2085);
    }

    @Test
    public void testScreenWidth() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();

        PixelUtil.initContext(context);
        int width = PixelUtil.screenWidth();
        Assert.assertTrue(width > 0);
        Assert.assertEquals(width, 1080);
    }

    @Test
    public void testScreenVp2px() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();

        PixelUtil.initContext(context);
        int width = (int) PixelUtil.vp2px(1);
        Assert.assertTrue(width == 3);
    }

    @Test
    public void testAnimationList() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        AnimationFramePool animationFramePool = new AnimationFramePool(16, 4);
        AnimationFrame frame = animationFramePool.obtain(EruptionAnimationFrame.TYPE);
        if(frame instanceof EruptionAnimationFrame) {
            EruptionAnimationFrame eruptionAnimationFrame = (EruptionAnimationFrame) frame;

            BitmapProvider.Provider hdProvider = BitmapProviderFactory.getHDProvider(context);
            List<Element> elements = eruptionAnimationFrame.generatedElements(0, 0, hdProvider);
            Assert.assertEquals(elements.size(), 4);
        }
        List<AnimationFrame> runningFrameList = animationFramePool.getRunningFrameList();
        List<AnimationFrame> idleFrameList = animationFramePool.getIdleFrameList();
        boolean hasRunningAnimation = animationFramePool.hasRunningAnimation();
        Assert.assertNotNull(runningFrameList);
        Assert.assertEquals(runningFrameList.size(), 1);
        Assert.assertEquals(idleFrameList.size(), 0);
        Assert.assertTrue(hasRunningAnimation);
    }

    @Test
    public void testCheckBitmapProvider() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        BitmapProvider.Provider hdProvider = BitmapProviderFactory.getHDProvider(context);
        PixelMap numberBitmap = hdProvider.getNumberBitmap(3);
        Assert.assertNotNull(numberBitmap);
        PixelMap levelBitmap = hdProvider.getLevelBitmap(2);
        Assert.assertNotNull(levelBitmap);
        PixelMap randomBitmap = hdProvider.getRandomBitmap();
        Assert.assertNotNull(randomBitmap);
    }
}